package com.xianggu.designMode.chainMethod.demo01;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chengjy
 * @date 2025/3/15
 */
public class FilterChain {

    private List<Filter> filters = new ArrayList<>();

    private int index = 0;

    public FilterChain addFilter(Filter filter){
        filters.add(filter);
        return this;
    }

    public void doFilter(Request request, Response response){
        if(index == filters.size()){
            return;
        }
        filters.get(index++).doFilter(request, response, this);
    }
}
